/*
 * Copyright (c) 2023 fred
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import { OutputSettings } from './OutputSettings';
import { Attributes } from './Attributes';
import { LeafNode } from './LeafNode';
import List from '@ohos.util.List';
import { Node } from './Node';

/**
 A data node, for contents of style, script tags etc, where contents should not show in text().
 */
export class DataNode extends LeafNode {
  constructor(data: string) {
    super()
    this.value = data
  }

  public nodeName(): string {
    return "#data"
  }
  /**
   Get the data contents of this node. Will be unescaped and with original new lines, space etc.
   @return data
   */
  public getWholeData(): string {
    return this.coreValue();
  }
  /**
   * Set the data contents of this node.
   * @param data unencoded data
   * @return this node, for chaining
   */
  public setWholeData(data: string): DataNode {
    this.setCoreValue(data);
    return this;
  }

  outerHtmlHead(accum: string[], depth: number, out: OutputSettings) {
    accum.push(this.getWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain
  }

  outerHtmlTail(accum: string[], depth: number, out: OutputSettings) {}

  public toString():string {
    return this.outerHtml()
  }

  public clone():DataNode {
    return super.clone() as DataNode
  }

}

